package com.lifeng.controller;

import com.lifeng.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by lifeng on 2019/5/9.
 */
@Controller
public class TestController {

    @RequestMapping("/test")
    public String addUI(Model model){
        model.addAttribute("name","张三");
        return "demo";
    }

    @RequestMapping("/testobj")
    public String addObject(Model model){
        User user = new User();
        user.setId("111");
        user.setName("张三");
        user.setAge(12);
        user.setBirthday(new Date());
        model.addAttribute("user",user);
        return "demo";
    }

    @RequestMapping("/list")
    public String list(Model model){
        List<User> list = new ArrayList<User>();
        User user = new User();
        user.setId("1");
        user.setName("张三");
        user.setAge(12);
        user.setBirthday(new Date());
        user.setSex(1);
        list.add(user);
        User user1 = new User();
        user1.setId("2");
        user1.setName("王五");
        user1.setAge(34);
        user1.setBirthday(new Date());
        user1.setSex(2);
        list.add(user1);

        User user3 = new User();
        user3.setId("3");
        user3.setName("李四");
        user3.setAge(25);
        user3.setBirthday(new Date());
        user3.setSex(3);
        list.add(user3);
        model.addAttribute("userList",list);

        User user2 = new User();
        user2.setId("111");
        user2.setName("张三");
        user2.setAge(12);
        user2.setBirthday(new Date());
        model.addAttribute("user",user2);
        return "demo";
    }
}
